import { handleResponse, Result } from "../util/handler";

export type Slider = {
  img: string;
  productId: number;
  storeId: number;
};

async function getSlider(): Promise<Result<Slider[]>> {
  return await fetch('/api/statistics/getSlider', {
    method: 'get',
    credentials: 'same-origin',
  }).then((resp) => handleResponse<Slider[]>(resp));
}

export type Statistics = {
  pay: number;
  time: number;
};

async function getUserStatistics({ month, token }: { month: number; token: string }): Promise<Result<Statistics>> {
  const params = new URLSearchParams({ month: ''+month });
  return await fetch(`/api/statistics/getUserStatistics?${params}`, {
    method: 'get',
    credentials: 'same-origin',
    headers: {
      token
    }
  }).then((resp) => handleResponse<Statistics>(resp));
}

export {
  getSlider,

  getUserStatistics
}